package com.cee.admin.modules.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cee.admin.common.BaseController;
import com.cee.common.web.result.Result;
import com.cee.domain.modules.sys.entity.SysUserLoginLog;
import com.cee.domain.modules.sys.query.SysUserLoginLogQuery;
import com.cee.domain.modules.sys.vo.SysLoginLogExportVo;
import com.cee.ds.common.constants.PermissionConstants;
import com.cee.ds.modules.sys.service.ISysUserLoginLogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author wsz
 * @since 2023/6/14
 */
@RestController
@RequestMapping("/api/v1/sys/user/loginLog")
@Tag(name = "系统用户-登录日志")
public class SysUserLoginLogController extends BaseController {

    @Autowired
    private ISysUserLoginLogService sysLoginLogService;

    @GetMapping("/page")
    @Operation(summary = "分页")
    @RequiresPermissions(PermissionConstants.SYS_BACKEND_LOG_PREFIX + PermissionConstants.READ)
    public Result<Page<SysUserLoginLog>> page(SysUserLoginLogQuery sysLoginLogQuery) {
        return success(sysLoginLogService.queryPageVo(sysLoginLogQuery.generatePage(), sysLoginLogQuery));
    }

    @PostMapping("/export")
    @Operation(summary = "导出")
    @RequiresPermissions(PermissionConstants.SYS_BACKEND_LOG_PREFIX + PermissionConstants.EXPORT)
    public void export(@RequestBody SysLoginLogExportVo exportVo) throws IOException {
        sysLoginLogService.export(exportVo, wrapDownloadResponse("登录日志.xlsx"));
    }
}
